-
Notifications
You must be signed in to change notification settings - Fork 123
Fix user-agent register timing in C++ and Unity SDK #1217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
73d3d33
to
9177497
Compare
Change to register user-agents before platform App creation so that the new user-agents can be captured and logged at iOS/Android level.
This utility function is used internally to ensure the callback is triggered when all necessary Java classes and methods are cached.
9177497
to
06bd6a2
Compare
❌ Integration test FAILEDRequested by @chkuang-g on commit 50828a9
Add flaky tests to go/fpl-cpp-flake-tracker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks good to me. I just added a few minor comments.
app/src/util_android.h
Outdated
// Make sure the Java classes and methods are cached before triggering the | ||
// the callback. Can be slow if this is called BEFORE any Firebase App is | ||
// created. | ||
void CallAfterEnsureMethodsCached(JNIEnv* env, jobject activity, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little bit strange to me that this is implemented in app_android.cc and the header is util_android.h.
I think the implementation makes sense to be in app_android.cc as it calls CacheMethods and I guess there is not currently an app_android.h file, so I suppose this is fine as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is.
I'm not sure if it is worth adding a app_android.h
just for this single function. And unfortunately the implementation has to live in app_android.cpp
so that it can access to all the JNI caching and releasing functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't the implementation in util_android, if it's not a method of App or related types like AppOptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CallAfterEnsureMethodsCached()
is an utility by nature but requires CacheMethods()
and ReleaseClasses()
which is only available in app_android.cpp
.
https://github.com/firebase/firebase-cpp-sdk/blob/main/app/src/app_android.cc
I can think of some alternative solutions
- Add
app_android.h
and declareCallAfterEnsureMethodsCached()
inapp_android.h
- Add
app_android.h
and declareCacheMethods()
andReleaseClasses()
so that they can be linked toutil_android.cpp
. Then moveCallAfterEnsureMethodsCached()
toutil_android.cpp
. - Move declaration and impl of
CacheMethods()
andReleaseClasses()
toutil_android
.
Do you see a risk to implement a function declare in util_android.h
but implemented in app_android.cpp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added app_android.h
🍞 Dismissed stale approval on external PR.
🍞 Dismissed stale approval on external PR.
The desktop test fail because the user-agent does not get registered again after the app is deleted an created again. Move the boolean to LibraryRegistry instance so that it can reset when the app is deleted.
🍞 Dismissed stale approval on external PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems mostly fine except for a few nits.
app/src/app_common.cc
Outdated
@@ -190,7 +190,7 @@ struct AppData { | |||
// Tracks library registrations. | |||
class LibraryRegistry { | |||
private: | |||
LibraryRegistry() {} | |||
LibraryRegistry() : is_common_libraries_registered(false) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: what about naming this, and the accessors, "Library" instead of "Libraries", as IsCommonLibraryRegistered is more correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
app/src/app_ios.mm
Outdated
@@ -277,7 +281,7 @@ static void PlatformOptionsToAppOptions(FIROptions* platform_options, AppOptions | |||
|
|||
App* App::GetInstance(const char* name) { return app_common::FindAppByName(name); } | |||
|
|||
void App::RegisterLibrary(const char* library, const char* version) { | |||
void App::RegisterLibrary(const char* library, const char* version, void* platform_resource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not used on this platform, do the /* platform_resource */ thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Also changed for desktop and stub
app/src/util_android.h
Outdated
// Make sure the Java classes and methods are cached before triggering the | ||
// the callback. Can be slow if this is called BEFORE any Firebase App is | ||
// created. | ||
void CallAfterEnsureMethodsCached(JNIEnv* env, jobject activity, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't the implementation in util_android, if it's not a method of App or related types like AppOptions?
- Rename `IsCommonLibrariesRegistered` to `IsCommonLibraryRegistered`, and similar changes. - Change function parameter `/* platform_resource */` for platforms which are not using this parameter - Move `CallAfterEnsureMethodsCached()` declaration to `app_android.h`
🍞 Dismissed stale approval on external PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change applied.
Description
Patch user-agent register timing in C++ and add utility functions for Unity SDK to register BEFORE C++ App is created.
Several notes:
util::GetJNIEnvFromApp()
is not reliable because it only works AFTER the first app is added.CallAfterEnsureMethodsCached()
functions is primarily for Unity SDK to register BEFORE C++ app is created, which is when the Java classes and methods are cached originally.Testing
Integration test. Manually E2E test for Android and iOS Auth testapp.
Type of Change
Place an
x
the applicable box:Notes
Release Notes
section ofrelease_build_files/readme.md
.